package com.spzx.product.api.factory;

import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.RemoteProductService;

import com.spzx.product.api.domain.*;
import com.spzx.product.api.domain.vo.SkuStockVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;
import java.util.Map;


//@Component 加到配置类内了，扫不扫描无所谓
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);
    @Override
    public RemoteProductService create(Throwable throwable) {
        log.info("远程调用【"+ ServiceNameConstants.PRODUCT_SERVICE +"】服务失败：");
        return new RemoteProductService() {
            @Override
            public R<List<ProductSku>> getTopSale(String resource) {
                return R.fail("获取首页畅销商品列表失败!"+throwable.getMessage());
            }

            @Override
            public R<TableDataInfo> skuList(Integer pageNum, Integer pageSize, SkuQuery skuQuery, String source) {
                return R.fail("查询商品列表失败！"+throwable.getMessage());
            }

            @Override
            public R<ProductSku> getProductSku(Long skuId,String source) {
                return R.fail("获取商品sku信息失败！"+throwable.getMessage());
            }

            @Override
            public R<Product> getProduct(Long id,String source) {
                return R.fail("获取商品信息失败！"+throwable.getMessage());
            }

            @Override
            public R<SkuPrice> getSkuPrice(Long skuId,String source) {
                return R.fail("获取商品sku最新价格信息失败！"+throwable.getMessage());
            }

            @Override
            public R<ProductDetails> getProductDetails(Long id,String source) {
                return R.fail("获取商品详细信息失败！"+throwable.getMessage());
            }

            @Override
            public R<Map<String, Long>> getSkuSpecValue(Long id,String source) {
                return R.fail("获取商品sku规则详细信息！"+throwable.getMessage());
            }

            @Override
            public R<SkuStockVo> getSkuStock(Long skuId,String source) {
                return R.fail("获取商品sku库存信息失败！"+throwable.getMessage());
            }
        };
    }
}
